package main

import (
	"fmt"
	cpl "sail/compile"
	"strings"
)

var _level = 1

func fprint(v string) {

	idstr := strings.Join(make([]string, _level), "    ")
	println(idstr + v)
}

func sub() {
	_level++
}

func endsub() {
	_level--
}

func printNode(part string, n interface{}) {
	fprint(part + " :")
	_level++

	switch n.(type) {

	case *cpl.BinaryExpr:
		t := n.(*cpl.BinaryExpr)
		_level++
		fprint("BinaryExpr:")
		sub()
		printNode("LHS", t.LHS)
		printNode("RHS", t.RHS)
		printNode("OP", t.Op)
		endsub()

	case *cpl.SubscrExpr:
		t := n.(*cpl.SubscrExpr)
		fprint("SubscrExpr:")
		sub()
		printNode("Left", t.Left)
		printNode("Right", t.Left)
		endsub()

	case *cpl.CellExpr:
		t := n.(*cpl.CellExpr)

		printNode("Value", t.Raw)

	default:
		fprint(fmt.Sprintf("%v", n))
	}

	_level--
}
